﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Business.WPF;
using Model;
using Presenters.WPF;
using Presenters.WPF.Views;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Students
{
    /// <summary>
    /// Interaction logic for SearchInscription.xaml
    /// </summary>
    public partial class SearchInscription : Window, ISearchInscriptionView
    {
        SearchInscriptionPresenter presenter;
        string Message;

        public SearchInscription()
        {
            InitializeComponent();
            presenter = new SearchInscriptionPresenter(this);
        }
        public string searchTextBox
        {
            get { return this.searchTB.Text; }
        }
        public bool isSearchBySubjectSigla //por codigo de materia
        {
            get { return this.searchBySubjectSiglaRB.IsChecked == true; }
        }
        public bool isSearchBySubjectCode
        {
            get { return this.searchBySubjectCodeRB.IsChecked == true; }
        }
        public bool isSearchBySubjectName
        {
            get { return this.searchBySubjectNameRB.IsChecked == true; }
        }
        public Collection<Inscription> inscriptionResults
        {
            set { this.InscriptionsResultsDG.ItemsSource = value; }
        }
        public string message
        {
            set { Message = value; }
        }
        public Inscription selectedInscription
        {
            get { return (Inscription)this.InscriptionsResultsDG.SelectedItem; }
        }

        private void searchTB_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (presenter != null)
            {
                presenter.SearchInscription();
            }
        }

        private void ViewInscriptionB_Click(object sender, RoutedEventArgs e)
        {
            if (this.InscriptionsResultsDG.SelectedItem != null)
            {
                NewInscription ni = new NewInscription((Inscription)this.InscriptionsResultsDG.SelectedItem, "isView","isView");
                ni.ShowDialog();
            }
            else
                MessageBox.Show("Primero seleccione la inscripcion de un estudiante!");
        }
        private void ModifyInscriptionB_Click(object sender, RoutedEventArgs e)
        {
            if (this.InscriptionsResultsDG.SelectedItem != null)
            {
                NewInscription ni = new NewInscription((Inscription)this.InscriptionsResultsDG.SelectedItem, "isModify");
                ni.ShowDialog();
                this.searchTB.Text = "";
            }
            else
                MessageBox.Show("Primero seleccione la inscripcion de un estudiante!");

        }
       

        private void searchTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            if (this.searchBySubjectCodeRB.IsChecked == true)
            {
                foreach (char ch in e.Text)
                {
                    if (!Char.IsDigit(ch))
                    {
                        e.Handled = true;
                    }
                }
            }
        }

    }
}
